////////////////////////////////////////////////////////////////////////////////
/// Midnight Circus 2007
////////////////////////////////////////////////////////////////////////////////

namespace GatherTogether
{
    namespace GatherDropRates
    {
        /// <summary>
        /// Class to describe the drop rates of gathered items from a specific continent.
        /// These continents include Kalimdor, Eastern Kingdoms, and Outlands.
        /// </summary>
        class Continent : System.Collections.Generic.IEnumerable<Area>
        {
            protected System.Collections.Generic.List<Area> m_areas = new System.Collections.Generic.List<Area>();

            public System.Collections.Generic.IEnumerator<Area> GetEnumerator()
            {
                foreach (Area area in m_areas)
                {
                    yield return area;
                }
            }

            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
            {
                return GetEnumerator();
            }

            public void AddArea(Area area)
            {
                m_areas.Add(area);
            }

            public void Merge(Continent otherContinent)
            {
                m_areas.Sort();

                foreach (Area area in otherContinent.m_areas)
                {
                    int index = m_areas.BinarySearch(area);

                    if (index < 0)
                    {
                        m_areas.Add(area);
                    }
                    else
                    {
                        foreach (Node node in area)
                        {
                            m_areas[index].AddNode(node);
                        }
                    }
                }
            }
        }
    }
}
